<template>
  <div class="app-container">
    <!-- 增删改查 -->
    <el-row style="margin: 15px 0" :gutter="10">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          v-hasPermi="['distribution:cloudGroup:add']"
          @click="handleAdd">
          {{ $t('创建分组') }}
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" />
    </el-row>
    <el-table v-loading="loading" ref="TableRef" :data="tableData" row-key="menuId">
      <el-table-column align="center" type="index" :label="$t('序号')" width="50" />
      <el-table-column align="center" show-overflow-tooltip prop="groupName" :label="$t('分组名')" />
      <el-table-column align="center" show-overflow-tooltip prop="sellerNum" :label="$t('不可见卖家数')" />
      <!-- 操作 -->
      <el-table-column align="center" fixed="right" :label="$t('操作')" :width="calWidth(200, 250, 200)">
        <template slot-scope="{ row }">
          <el-button
            type="text"
            size="small"
            @click="handleDetail(row)"
            v-hasPermi="['distribution:cloudGroup:getCloudGroupSellerListIs']">
            {{ $t('查看卖家') }}
          </el-button>
          <el-button
            type="text"
            size="small"
            @click="handleEdit(row)"
            v-hasPermi="['distribution:cloudGroup:update']">
            {{ $t('修改分组') }}
          </el-button>
          <el-button
            type="text"
            v-hasPermi="['distribution:cloudGroup:delete']"
            size="small"
            @click="handleDelete(row)">
            {{ $t('删除分组') }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <AddAndEdit
      :show.sync="addAndEdit.show"
      @getList="getList"
      :formData="addAndEdit.formData"
      :type="addAndEdit.type" />
    <GroupSeller
      :show.sync="groupSeller.show"
      @getList="getList"
      :formData="groupSeller.formData"
      :title="groupSeller.formData.groupName"
      :groupId="groupSeller.formData.id"
      :type="groupSeller.type" />
  </div>
</template>

<script>
import { list, deleteCloudGroup } from '@/api/platform/cloudInvisibleGroup'
import AddAndEdit from './addAndEdit.vue'
import GroupSeller from '@/components/groupSeller/index.vue'

export default {
  activated() {
    this.$nextTick(() => this.$refs['TableRef']?.doLayout())
  },
  name: 'CloudInvisibleGroup',
  components: { AddAndEdit, GroupSeller },
  data() {
    return {
      showSearch: true,
      /**审核 */
      addAndEdit: {
        show: false,
        type: '',
        formData: {},
      },
      /**分组卖家 */
      groupSeller: {
        show: false,
        type: '',
        formData: {},
      },
      form: {},
      tableCheck: [],
      tableData: [],
      /**数据总条数 */
      total: 0,
      loading: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
    }
  },
  async created() {
    this.getList()
  },

  methods: {
    handleAdd() {
      this.addAndEdit.show = true
      this.addAndEdit.type = 'add'
    },
    handleEdit(row) {
      this.addAndEdit.show = true
      this.addAndEdit.type = 'edit'
      this.addAndEdit.formData = JSON.parse(JSON.stringify(row))
    },
    handleDetail(row) {
      this.groupSeller.show = true
      this.groupSeller.type = 'edit'
      this.groupSeller.formData = JSON.parse(JSON.stringify(row))
    },
    handleDelete(row) {
      this.$confirm(this.$t('确认删除?'), this.$t('提示'), {
        type: 'warning',
      })
        .then(() => {
          deleteCloudGroup(row.id).then((res) => {
            const { code, data, msg } = res
            if (code === 200) {
              this.$message({ type: 'success', message: msg })
              this.getList()
            }
          })
        })
        .catch((e) => e)
    },
    /** 查询菜单列表 */
    getList() {
      this.loading = true
      list(this.queryParams).then((res) => {
        this.tableData = res.rows
        this.total = res.total
        this.loading = false
      })
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.value1 = null
      Object.keys(this.queryParams).forEach((key) => {
        this.queryParams[key] = null
      })
      this.queryParams.pageNum = 1
      this.queryParams.pageSize = 10

      this.getList()
    },
  },
}
</script>
<style lang="scss" scoped></style>
